/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Ashe Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/
 * @date:        2020/1/11 4:35 下午
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.yi.yier.boot.autoconfigure.hello;

import com.yi.yier.boot.autoconfigure.hello.bean.HelloYierBootService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * </p>
 *
 * @author Ashe
 * @version V1.0.0
 * @date 2020/1/11 4:35 下午
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人}  2020/1/11
 * @modify reason: {方法名}:{原因}
 * ...
 */
@Configuration
@EnableConfigurationProperties(HelloProperties.class)
@ConditionalOnClass({HelloYierBootService.class,RestController.class})
@ConditionalOnProperty(prefix = "yier.boot.hello", value = "enabled", matchIfMissing = true)
@ComponentScan(basePackages = {"com.yi.yier.boot.autoconfigure.hello.bean"})
@Slf4j
public class HelloAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(HelloYierBootService.class)
    public HelloYierBootService helloWorldService(HelloProperties helloProperties) {
        log.info("HelloAutoConfiguration >> register HelloSummerBootService has started!");
        return HelloYierBootService.builder().name(helloProperties.getName()).message(helloProperties.getMessage()).build();
    }

}
